home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / editors / stevie3a.2 < prev    next >
Text File  |  1989-03-15  |  48KB  |  1,811 lines

  1. Path: xanth!lll-winken!ames!mailrus!bbn!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i041:  stevie - vi-like text editor v35a, Part02/06
  5. Message-ID: <12214@swan.ulowell.edu>
  6. Date: 15 Mar 89 14:56:50 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 1800
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: grwalter@watcgl.waterloo.edu (Fred Walter)
  12. Posting-number: Volume 89, Issue 41
  13. Archive-name: editors/stevie35a.2
  14.  
  15. #    This is a shell archive.
  16. #    Remove everything above and including the cut line.
  17. #    Then run the rest of the file through sh.
  18. #----cut here-----cut here-----cut here-----cut here----#
  19. #!/bin/sh
  20. # shar:    Shell Archiver
  21. #    Run the following text with /bin/sh to create:
  22. #    alloc.c
  23. #    amiga.c
  24. #    fileio.c
  25. #    os2.c
  26. #    stevie.h
  27. #    tags
  28. #    term.h
  29. #    tos.h
  30. #    version.c
  31. # This archive created: Tue Mar 14 14:41:09 1989
  32. cat << \SHAR_EOF > alloc.c
  33. /*
  34.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  35.  *
  36.  * Code Contributions By : Tim Thompson           twitch!tjt
  37.  *                         Tony Andrews           onecom!wldrdg!tony 
  38.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  39.  */
  40.  
  41. #include "stevie.h"
  42.  
  43. /*
  44.  * This file contains various routines dealing with allocation and
  45.  * deallocation of data structures. 
  46.  */
  47.  
  48. char           *
  49. alloc(size)
  50.     unsigned        size;
  51. {
  52.     char           *p;        /* pointer to new storage space */
  53. #ifdef AMIGA
  54.     char           *pp;
  55.  
  56.     /*
  57.      * Before allocating any memory make sure there is enough for a system
  58.      * requester left. 
  59.      */
  60.     pp = malloc((unsigned) 40000);
  61.     if (pp == (char *) NULL) {    /* if there is no more room... */
  62.     emsg("alloc() is unable to find memory!");
  63.     return (NULL);
  64.     }
  65. #endif
  66.  
  67.     p = malloc(size);
  68.     if (p == (char *) NULL)    /* if there is no more room... */
  69.     emsg("alloc() is unable to find memory!");
  70.  
  71. #ifdef AMIGA
  72.     free(pp);
  73. #endif
  74.     return (p);
  75. }
  76.  
  77. char           *
  78. strsave(string)
  79.     char           *string;
  80. {
  81.     return (strcpy(alloc((unsigned) (strlen(string) + 1)), string));
  82. }
  83.  
  84. void
  85. screenalloc()
  86. {
  87.     int             i;
  88.  
  89.     /*
  90.      * If we're changing the size of the screen, free the old arrays 
  91.      */
  92.     if (Realscreen != NULL)
  93.     free(Realscreen);
  94.     if (Nextscreen != NULL)
  95.     free(Nextscreen);
  96.     if (LinePointers != NULL)
  97.     free((char *) LinePointers);
  98.     if (LineSizes != NULL)
  99.     free(LineSizes);
  100.  
  101.     Realscreen = malloc((unsigned) (Rows * Columns));
  102.     Nextscreen = malloc((unsigned) (Rows * Columns));
  103.     LinePointers = (LINE **) malloc((unsigned) (Rows * sizeof(LINE *)));
  104.     LineSizes = malloc((unsigned) Rows);
  105.  
  106.     for (i = 0; i < Rows; i++) {
  107.     LinePointers[i] = NULL;
  108.     LineSizes[i] = 0;
  109.     }
  110. }
  111.  
  112. /*
  113.  * Allocate and initialize a new line structure with room for 'nchars'
  114.  * characters. 
  115.  */
  116. LINE           *
  117. newline(nchars)
  118.     int             nchars;
  119. {
  120.     register LINE  *l;
  121.  
  122.     l = (LINE *) alloc((unsigned) sizeof(LINE));
  123.     if (l == NULL)
  124.     return (LINE *) NULL;
  125.  
  126.     l->s = alloc((unsigned) nchars);    /* the line is empty */
  127.     l->s[0] = NUL;
  128.     l->size = nchars;
  129.  
  130.     l->prev = (LINE *) NULL;    /* should be initialized by caller */
  131.     l->next = (LINE *) NULL;
  132.  
  133.     return l;
  134. }
  135.  
  136. /*
  137.  * filealloc() - construct an initial empty file buffer 
  138.  */
  139. void
  140. filealloc()
  141. {
  142.     if ((Filemem->linep = newline(1)) == NULL) {
  143.     fprintf(stderr, "Unable to allocate file memory!\n");
  144.     getout(1);
  145.     }
  146.     if ((Filetop->linep = newline(1)) == NULL) {
  147.     fprintf(stderr, "Unable to allocate file memory!\n");
  148.     getout(1);
  149.     }
  150.     if ((Fileend->linep = newline(1)) == NULL) {
  151.     fprintf(stderr, "Unable to allocate file memory!\n");
  152.     getout(1);
  153.     }
  154.     Filemem->index = 0;
  155.     Filetop->index = 0;
  156.     Fileend->index = 0;
  157.  
  158.     Filetop->linep->prev = NULL;
  159.     Filetop->linep->next = Filemem->linep;    /* connect Filetop to Filemem */
  160.     Filemem->linep->prev = Filetop->linep;
  161.  
  162.     Filemem->linep->next = Fileend->linep;    /* connect Filemem to Fileend */
  163.     Fileend->linep->prev = Filemem->linep;
  164.     Fileend->linep->next = NULL;
  165.  
  166.     *Curschar = *Filemem;
  167.     *Topchar = *Filemem;
  168.  
  169.     Filemem->linep->num = 0;
  170.     Fileend->linep->num = 0xffffffffL;
  171.  
  172.     clrall();            /* clear all marks */
  173. }
  174.  
  175. /*
  176.  * freeall() - free the current buffer 
  177.  *
  178.  * Free all lines in the current buffer. 
  179.  */
  180. void
  181. freeall()
  182. {
  183.     LINE           *lp;
  184.     LINE           *xlp;
  185.     int             i;
  186.  
  187.     for (lp = Filetop->linep; lp != NULL; lp = xlp) {
  188.     if (lp->s != NULL)
  189.         free(lp->s);
  190.     xlp = lp->next;
  191.     free((char *) lp);
  192.     }
  193.  
  194.     Curschar->linep = NULL;    /* clear pointers */
  195.     Filemem->linep = NULL;
  196.     Filetop->linep = NULL;
  197.     Fileend->linep = NULL;
  198.  
  199.     for (i = 0; i < Rows; i++) {/* clear screen information */
  200.     LinePointers[i] = NULL;
  201.     LineSizes[i] = 0;
  202.     }
  203. }
  204.  
  205. /*
  206.  * canincrease(n) - returns TRUE if the current line can be increased 'n'
  207.  * bytes 
  208.  *
  209.  * This routine returns immediately if the requested space is available. If not,
  210.  * it attempts to allocate the space and adjust the data structures
  211.  * accordingly. If everything fails it returns FALSE. 
  212.  */
  213. bool_t
  214. canincrease(n)
  215.     register int    n;
  216. {
  217.     register int    nsize;
  218.     register char  *s;        /* pointer to new space */
  219.  
  220.     nsize = strlen(Curschar->linep->s) + 1 + n;    /* size required */
  221.  
  222.     if (nsize <= Curschar->linep->size)
  223.     return TRUE;
  224.  
  225.     /*
  226.      * Need to allocate more space for the string. Allow some extra space on
  227.      * the assumption that we may need it soon. This avoids excessive numbers
  228.      * of calls to malloc while entering new text. 
  229.      */
  230.     s = alloc((unsigned) (nsize + SLOP));
  231.     if (s == NULL) {
  232.     emsg("Can't add anything, file is too big!");
  233.     State = NORMAL;
  234.     return FALSE;
  235.     }
  236.     Curschar->linep->size = nsize + SLOP;
  237.     strcpy(s, Curschar->linep->s);
  238.     free(Curschar->linep->s);
  239.     Curschar->linep->s = s;
  240.  
  241.     return TRUE;
  242. }
  243. SHAR_EOF
  244. cat << \SHAR_EOF > amiga.c
  245. /*
  246.  * Amiga system-dependent routines. 
  247.  */
  248.  
  249. #include <proto/dos.h>
  250. #include "stevie.h"
  251.  
  252. long            raw_in = 0;
  253. long            raw_out = 0;
  254.  
  255. #define    BSIZE    2048
  256. static char     outbuf[BSIZE];
  257. static int      bpos = 0;
  258.  
  259. void
  260. flushbuf()
  261. {
  262.     if (bpos != 0)
  263.     Write(raw_out, outbuf, bpos);
  264.     bpos = 0;
  265. }
  266.  
  267. /*
  268.  * Macro to output a character. Used within this file for speed. 
  269.  */
  270. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  271.  
  272. int
  273. GetCharacter()
  274. {
  275.     char            c;
  276.  
  277.     Read(raw_in, &c, sizeof(c));
  278.     return ((int) c);
  279. }
  280.  
  281. /*
  282.  * getCSIsequence - get a CSI sequence
  283.  *                - either cursor keys, help, functionkeys, or some
  284.  *                  other sequence (if other, check window size)
  285.  */
  286. int
  287. getCSIsequence()
  288. {
  289.     int             c;
  290.     int             param1;
  291.     int             param2;
  292.  
  293.     c = GetCharacter();
  294.     if (isdigit(c)) {
  295.     param1 = 0;
  296.     while (isdigit(c)) {
  297.         param1 = param1 * 10 + c - '0';
  298.         c = GetCharacter();
  299.     }
  300.     if (c == '~')        /* function key */
  301.         return ((char) (K_F1 + param1));
  302.  
  303.     /* must be an event of some sort or a window bound report */
  304.     if (c == ';') {
  305.         param2 = 0;
  306.         c = GetCharacter();
  307.         while (isdigit(c)) {
  308.         param2 = param2 * 10 + c - '0';
  309.         c = GetCharacter();
  310.         }
  311.         if (c == ';') {
  312.         param1 = 0;
  313.         c = GetCharacter();
  314.         while (isdigit(c)) {
  315.             param1 = param1 * 10 + c - '0';
  316.             c = GetCharacter();
  317.         }
  318.         if (c == ';') {
  319.             param2 = 0;
  320.             c = GetCharacter();
  321.             while (isdigit(c)) {
  322.             param2 = param2 * 10 + c - '0';
  323.             c = GetCharacter();
  324.             }
  325.             if (c == ' ') {
  326.             c = GetCharacter();
  327.             if (c == 'r') {
  328.                 if (param1 < 2)
  329.                 param1 = 2;
  330.                 if (param2 < 5)
  331.                 param2 = 5;
  332.                 if (Columns != param2 || Rows != param1) {
  333.                 Columns = param2;
  334.                 Rows = param1;
  335.                 P(P_LI) = Rows;
  336.                 return (-1);
  337.                 } else
  338.                 return 0;
  339.             }
  340.             }
  341.         }
  342.         }
  343.     }
  344.     while ((c != '|') && (c != '~'))
  345.         c = GetCharacter();
  346.  
  347.     outstr("\033[0 q");
  348.     flushbuf();
  349.     }
  350.     switch (c) {
  351.       case 'A':        /* cursor up */
  352.     return K_UARROW;
  353.       case 'B':        /* cursor down */
  354.     return K_DARROW;
  355.       case 'C':        /* cursor right */
  356.     return K_RARROW;
  357.       case 'D':        /* cursor left */
  358.     return K_LARROW;
  359.       case 'T':        /* shift cursor up */
  360.     return K_SUARROW;
  361.       case 'S':        /* shift cursor down */
  362.     return K_SDARROW;
  363.       case ' ':        /* shift cursor left or right */
  364.     c = GetCharacter();
  365.     if (c == 'A')        /* shift cursor left */
  366.         return K_SLARROW;
  367.     if (c == '@')        /* shift cursor right */
  368.         return K_SRARROW;
  369.     break;
  370.       case '?':        /* help */
  371.     c = GetCharacter();
  372.     if (c == '~')
  373.         return K_HELP;
  374.     break;
  375.     }
  376.     return 0;            /* some other control code */
  377. }
  378.  
  379. /*
  380.  * inchar() - get a character from the keyboard 
  381.  */
  382. int
  383. inchar()
  384. {
  385.     int             c;
  386.  
  387.     flushbuf();
  388.  
  389.     for (;;) {
  390.     c = GetCharacter();
  391.     if (c != 0x9b)
  392.         break;
  393.     c = getCSIsequence();
  394.     if (c > 0)
  395.         break;
  396.     if (c == -1) {
  397.         screenalloc();
  398.         screenclear();
  399.         msg("");
  400.         updateNextscreen(NOT_VALID);
  401.         cursupdate();
  402.         updateNextscreen(NOT_VALID);
  403.         cursupdate();
  404.         updateRealscreen();
  405.         windgoto(Cursrow, Curscol);
  406.         flushbuf();
  407.     }
  408.     }
  409.     return c;
  410. }
  411.  
  412. void
  413. outchar(c)
  414.     char            c;
  415. {
  416.     outbuf[bpos++] = c;
  417.     if (bpos >= BSIZE)
  418.     flushbuf();
  419. }
  420.  
  421. void
  422. outstr(s)
  423.     char           *s;
  424. {
  425.     while (*s)
  426.     outone(*s++);
  427. }
  428.  
  429. void
  430. beep()
  431. {
  432.     if (RedrawingDisabled)
  433.     return;
  434.  
  435.     outone('\007');
  436. }
  437.  
  438. void
  439. sleep(n)
  440.     int             n;
  441. {
  442.     void            Delay();
  443.  
  444.     if (n > 0)
  445.     Delay(50L * n);
  446. }
  447.  
  448. void
  449. delay()
  450. {
  451.     void            Delay();
  452.  
  453.     Delay(25L);
  454. }
  455.  
  456. void
  457. windinit()
  458. {
  459.     Columns = 80;
  460.     P(P_LI) = Rows = 24;
  461.  
  462.     raw_in = Input();
  463.     if (!IsInteractive(raw_in)) {
  464.     raw_in = Open("RAW:0/0/480/200/STEVIE", MODE_NEWFILE);
  465.     if (raw_in == NULL) {
  466.         fprintf(stderr, "Can't open window ?!?!?!?\n");
  467.         exit(2);
  468.     }
  469.     raw_out = raw_in;
  470.     } else {
  471.     raw_out = Output();
  472.     if (raw(stdin) != 0)
  473.         perror("Can't change to raw mode ?!?!?!?");
  474.     }
  475.  
  476.     outstr("\033[12{");        /* window resize events activated */
  477.     flushbuf();
  478.  
  479.     for (;;) {
  480.     outstr("\033[0 q");    /* get window size */
  481.     flushbuf();
  482.     if (GetCharacter() == 0x9b)
  483.         if (getCSIsequence() == -1)
  484.         break;
  485.     }
  486. }
  487.  
  488. void
  489. windexit(r)
  490.     int             r;
  491. {
  492.     outstr("\033[12}");        /* window resize events de-activated */
  493.     flushbuf();
  494.  
  495.     if (raw_in != raw_out) {
  496.     if (cooked(stdin) != 0)
  497.         perror("Can't change to cooked mode ?!?!?!?");
  498.     } else {
  499.     Close(raw_in);
  500.     }
  501.     exit(r);
  502. }
  503.  
  504. void
  505. windgoto(r, c)
  506.     int             c;
  507.     int             r;
  508. {
  509.     r++;
  510.     c++;
  511.  
  512.     outstr("\033[");
  513.     if (r >= 10)
  514.     outchar((char) (r / 10 + '0'));
  515.     outchar((char) (r % 10 + '0'));
  516.     outchar(';');
  517.     if (c >= 10)
  518.     outchar((char) (c / 10 + '0'));
  519.     outchar((char) (c % 10 + '0'));
  520.     outchar('H');
  521. }
  522.  
  523. FILE           *
  524. fopenb(fname, mode)
  525.     char           *fname;
  526.     char           *mode;
  527. {
  528.     FILE           *fopen();
  529.     char            modestr[16];
  530.  
  531.     sprintf(modestr, "%sb", mode);
  532.     return fopen(fname, modestr);
  533. }
  534. SHAR_EOF
  535. cat << \SHAR_EOF > fileio.c
  536. /*
  537.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  538.  *
  539.  * Code Contributions By : Tim Thompson           twitch!tjt
  540.  *                         Tony Andrews           onecom!wldrdg!tony 
  541.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  542.  */
  543.  
  544. #include "stevie.h"
  545.  
  546. void
  547. filemess(s)
  548.     char           *s;
  549. {
  550.     sprintf(IObuff, "\"%s\" %s", ((Filename == NULL) ? "" : Filename), s);
  551.     msg(IObuff);
  552. }
  553.  
  554. void
  555. renum()
  556. {
  557.     LPtr           *p;
  558.     unsigned long   l = 0;
  559.  
  560.     for (p = Filemem; p != NULL; p = nextline(p), l += LINEINC)
  561.     p->linep->num = l;
  562.  
  563.     Fileend->linep->num = 0xffffffffL;
  564. }
  565.  
  566. #ifdef    MEGAMAX
  567. overlay "fileio"
  568. #endif
  569.  
  570. bool_t
  571. readfile(fname, fromp, nochangename)
  572.     char           *fname;
  573.     LPtr           *fromp;
  574.     bool_t          nochangename;    /* if TRUE, don't change the Filename */
  575. {
  576.     FILE           *f, *fopen();
  577.     LINE           *curr;
  578.     char            buf2[80];
  579.     int             c;
  580.     int             IObuffsize = 0;
  581.     long            nchars = 0;
  582.     int             linecnt = 0;
  583.     bool_t          wasempty = bufempty();
  584.     int             nonascii = 0;    /* count garbage characters */
  585.     int             nulls = 0;    /* count nulls */
  586.     bool_t          incomplete = FALSE;    /* was the last line incomplete? */
  587.     bool_t          toolong = FALSE;    /* a line was too long */
  588.  
  589.     curr = fromp->linep;
  590.  
  591.     if (!nochangename)
  592.     Filename = strsave(fname);
  593.  
  594.     f = fopen(fname, "r");
  595.     if (f == NULL)
  596.     return TRUE;
  597.  
  598.     filemess("");
  599.  
  600.     do {
  601.     c = getc(f);
  602.  
  603.     if (c == EOF) {
  604.         if (IObuffsize == 0)/* normal loop termination */
  605.         break;
  606.  
  607.         /*
  608.          * If we get EOF in the middle of a line, note the fact and
  609.          * complete the line ourselves. 
  610.          */
  611.         incomplete = TRUE;
  612.         c = NL;
  613.     }
  614.     if (c >= 0x80) {
  615.         c -= 0x80;
  616.         nonascii++;
  617.     }
  618.     /*
  619.      * If we reached the end of the line, OR we ran out of space for it,
  620.      * then process the complete line. 
  621.      */
  622.     if (c == NL || IObuffsize == (IOSIZE - 1)) {
  623.         LINE           *lp;
  624.  
  625.         if (c != NL)
  626.         toolong = TRUE;
  627.  
  628.         IObuff[IObuffsize++] = NUL;
  629.         if ((lp = newline(IObuffsize)) == NULL) {
  630.         fprintf(stderr, "not enough memory - should never happen");
  631.         getout(1);
  632.         }
  633.         strcpy(lp->s, IObuff);
  634.  
  635.         curr->next->prev = lp;    /* new line to next one */
  636.         lp->next = curr->next;
  637.  
  638.         curr->next = lp;    /* new line to prior one */
  639.         lp->prev = curr;
  640.  
  641.         curr = lp;        /* new line becomes current */
  642.         IObuffsize = 0;
  643.         linecnt++;
  644.     } else if (c == NUL) {
  645.         nulls++;        /* count and ignore nulls */
  646.     } else {
  647.         IObuff[IObuffsize++] = (char) c;    /* normal character */
  648.     }
  649.  
  650.     nchars++;
  651.     } while (!incomplete && !toolong);
  652.  
  653.     fclose(f);
  654.  
  655.     /*
  656.      * If the buffer was empty when we started, we have to go back and remove
  657.      * the "dummy" line at Filemem and patch up the ptrs. 
  658.      */
  659.     if (wasempty && linecnt != 0) {
  660.     LINE           *dummy = Filemem->linep;    /* dummy line ptr */
  661.  
  662.     free(dummy->s);        /* free string space */
  663.     Filemem->linep = Filemem->linep->next;
  664.     free((char *) dummy);    /* free LINE struct */
  665.     Filemem->linep->prev = Filetop->linep;
  666.     Filetop->linep->next = Filemem->linep;
  667.  
  668.     Curschar->linep = Filemem->linep;
  669.     Topchar->linep = Filemem->linep;
  670.     }
  671.     renum();
  672.  
  673.     if (toolong) {
  674.     sprintf(IObuff, "\"%s\" Line too long", fname);
  675.     msg(IObuff);
  676.     return FALSE;
  677.     }
  678.     sprintf(IObuff, "\"%s\" %s%d line%s, %ld character%s",
  679.         fname,
  680.         incomplete ? "[Incomplete last line] " : "",
  681.         linecnt, (linecnt > 1) ? "s" : "",
  682.         nchars, (nchars > 1) ? "s" : "");
  683.  
  684.     buf2[0] = NUL;
  685.  
  686.     if (nonascii || nulls) {
  687.     if (nonascii) {
  688.         if (nulls)
  689.         sprintf(buf2, " (%d null, %d non-ASCII)",
  690.             nulls, nonascii);
  691.         else
  692.         sprintf(buf2, " (%d non-ASCII)", nonascii);
  693.     } else
  694.         sprintf(buf2, " (%d null)", nulls);
  695.     }
  696.     strcat(IObuff, buf2);
  697.     msg(IObuff);
  698.  
  699.     return FALSE;
  700. }
  701.  
  702. /*
  703.  * writeit - write to file 'fname' lines 'start' through 'end' 
  704.  *
  705.  * If either 'start' or 'end' contain null line pointers, the default is to use
  706.  * the start or end of the file respectively. 
  707.  */
  708. bool_t
  709. writeit(fname, start, end)
  710.     char           *fname;
  711.     LPtr           *start, *end;
  712. {
  713.     FILE           *f, *fopen();
  714.     FILE           *fopenb();    /* open in binary mode, where needed */
  715.     char           *backup, *s;
  716.     long            nchars;
  717.     int             lines;
  718.     LPtr           *p;
  719.  
  720.     sprintf(IObuff, "\"%s\"", fname);
  721.     msg(IObuff);
  722.  
  723.     /*
  724.      * Form the backup file name - change foo.* to foo.bak 
  725.      */
  726.     backup = alloc((unsigned) (strlen(fname) + 5));
  727.     strcpy(backup, fname);
  728.     for (s = backup; *s && *s != '.'; s++);
  729.     *s = NUL;
  730.     strcat(backup, ".bak");
  731.  
  732.     /*
  733.      * Delete any existing backup and move the current version to the backup.
  734.      * For safety, we don't remove the backup until the write has finished
  735.      * successfully. And if the 'backup' option is set, leave it around. 
  736.      */
  737.     rename(fname, backup);
  738.  
  739.     f = P(P_CR) ? fopen(fname, "w") : fopenb(fname, "w");
  740.  
  741.     if (f == NULL) {
  742.     emsg("Can't open file for writing!");
  743.     free((char *) backup);
  744.     return FALSE;
  745.     }
  746.     /*
  747.      * If we were given a bound, start there. Otherwise just start at the
  748.      * beginning of the file. 
  749.      */
  750.     if (start == NULL || start->linep == NULL)
  751.     p = Filemem;
  752.     else
  753.     p = start;
  754.  
  755.     lines = 0;
  756.     nchars = 0;
  757.     do {
  758.     fprintf(f, "%s\n", p->linep->s);
  759.     nchars += strlen(p->linep->s) + 1;
  760.     lines++;
  761.  
  762.     /*
  763.      * If we were given an upper bound, and we just did that line, then
  764.      * bag it now. 
  765.      */
  766.     if (end != NULL && end->linep != NULL) {
  767.         if (end->linep == p->linep)
  768.         break;
  769.     }
  770.     } while ((p = nextline(p)) != NULL);
  771.  
  772.     fclose(f);
  773.     sprintf(IObuff, "\"%s\" %d line%s, %ld character%s", fname,
  774.         lines, (lines > 1) ? "s" : "",
  775.         nchars, (nchars > 1) ? "s" : "");
  776.     msg(IObuff);
  777.     UNCHANGED;
  778.  
  779.     /*
  780.      * Remove the backup unless they want it left around 
  781.      */
  782.     if (!P(P_BK))
  783.     remove(backup);
  784.  
  785.     free((char *) backup);
  786.  
  787.     return TRUE;
  788. }
  789. SHAR_EOF
  790. cat << \SHAR_EOF > os2.c
  791. /*
  792.  * OS/2 System-dependent routines.
  793.  *
  794.  * $Log:    os2.c,v $
  795.  * Revision 1.2  88/04/25  16:50:19  tony
  796.  * Minor changes for OS/2 version 1.1; also fixed up the RCS header.
  797.  * 
  798.  * Revision 1.1  88/03/21  12:04:23  tony
  799.  * Initial revision
  800.  * 
  801.  *
  802.  */
  803.  
  804. #define    INCL_BASE
  805. #include <os2.h>
  806. #include "stevie.h"
  807.  
  808. /*
  809.  * inchar() - get a character from the keyboard
  810.  */
  811. int
  812. inchar()
  813. {
  814.     int             c;
  815.  
  816.     for (;; beep()) {        /* loop until we get a valid character */
  817.  
  818.     flushbuf();        /* flush any pending output */
  819.  
  820.     switch (c = getch()) {
  821.       case 0x1e:
  822.         return K_CGRAVE;
  823.       case 0:        /* special key */
  824.       case 0xe0:        /* special key */
  825.         if (State != NORMAL) {
  826.         c = getch();    /* throw away next char */
  827.         continue;    /* and loop for another char */
  828.         }
  829.         switch (c = getch()) {
  830.           case 0x50:
  831.         return K_DARROW;
  832.           case 0x48:
  833.         return K_UARROW;
  834.           case 0x4b:
  835.         return K_LARROW;
  836.           case 0x4d:
  837.         return K_RARROW;
  838.           case 0x52:
  839.         return K_INSERT;
  840.           case 0x47:
  841.         stuffReadbuff("1G");
  842.         return -1;
  843.           case 0x4f:
  844.         stuffReadbuff("G");
  845.         return -1;
  846.           case 0x51:
  847.         stuffReadbuff(mkstr(CTRL('F')));
  848.         return -1;
  849.           case 0x49:
  850.         stuffReadbuff(mkstr(CTRL('B')));
  851.         return -1;
  852.         /*
  853.          * Hard-code some useful function key macros. 
  854.          */
  855.           case 0x3b:    /* F1 */
  856.         stuffReadbuff(":p\n");
  857.         return -1;
  858.           case 0x54:    /* SF1 */
  859.         stuffReadbuff(":p!\n");
  860.         return -1;
  861.           case 0x3c:    /* F2 */
  862.         stuffReadbuff(":n\n");
  863.         return -1;
  864.           case 0x55:    /* SF2 */
  865.         stuffReadbuff(":n!\n");
  866.         return -1;
  867.           case 0x3d:    /* F3 */
  868.         stuffReadbuff(":e #\n");
  869.         return -1;
  870.           case 0x3e:    /* F4 */
  871.         stuffReadbuff(":rew\n");
  872.         return -1;
  873.           case 0x57:    /* SF4 */
  874.         stuffReadbuff(":rew!\n");
  875.         return -1;
  876.           case 0x3f:    /* F5 */
  877.         stuffReadbuff("[[");
  878.         return -1;
  879.           case 0x40:    /* F6 */
  880.         stuffReadbuff("]]");
  881.         return -1;
  882.           case 0x41:    /* F7 */
  883.         stuffReadbuff("<<");
  884.         return -1;
  885.           case 0x42:    /* F8 */
  886.         stuffReadbuff(">>");
  887.         return -1;
  888.           case 0x43:    /* F9 */
  889.         stuffReadbuff(":x\n");
  890.         return -1;
  891.           case 0x44:    /* F10 */
  892.         stuffReadbuff(":help\n");
  893.         return -1;
  894.           default:
  895.         break;
  896.         }
  897.         break;
  898.  
  899.       default:
  900.         return c;
  901.     }
  902.     }
  903. }
  904.  
  905. #define    BSIZE    2048
  906. static char     outbuf[BSIZE];
  907. static int      bpos = 0;
  908.  
  909. flushbuf()
  910. {
  911.     if (bpos != 0)
  912.     write(1, outbuf, bpos);
  913.     bpos = 0;
  914. }
  915.  
  916. /*
  917.  * Macro to output a character. Used within this file for speed.
  918.  */
  919. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  920.  
  921. /*
  922.  * Function version for use outside this file.
  923.  */
  924.  
  925. void
  926. outchar(c)
  927.     register char   c;
  928. {
  929.     outbuf[bpos++] = c;
  930.     if (bpos >= BSIZE)
  931.     flushbuf();
  932. }
  933.  
  934. static char     cell[2] = {0, 7};
  935.  
  936. /*
  937.  * outstr(s) - write a string to the console
  938.  *
  939.  * We implement insert/delete line escape sequences here. This is kind
  940.  * of a kludge, but at least it's localized to a single point.
  941.  */
  942. void
  943. outstr(s)
  944.     register char  *s;
  945. {
  946.     if (strcmp(s, T_DL) == 0) {    /* delete line */
  947.     int             r, c;
  948.  
  949.     flushbuf();
  950.     VioGetCurPos(&r, &c, 0);
  951.     VioScrollUp(r, 0, 100, 100, 1, cell, 0);
  952.     return;
  953.     }
  954.     if (strcmp(s, T_IL) == 0) {    /* insert line */
  955.     int             r, c;
  956.  
  957.     flushbuf();
  958.     VioGetCurPos(&r, &c, 0);
  959.     VioScrollDn(r, 0, 100, 100, 1, cell, 0);
  960.     return;
  961.     }
  962.     while (*s) {
  963.     outone(*s++);
  964.     }
  965. }
  966.  
  967. void
  968. beep()
  969. {
  970.     if (RedrawingDisabled)
  971.     return;
  972.  
  973.     outone('\007');
  974. }
  975.  
  976. void
  977. sleep(n)
  978.     int             n;
  979. {
  980.     DosSleep(1000L * n);
  981. }
  982.  
  983. void
  984. delay()
  985. {
  986.     flushbuf();
  987.     DosSleep(300L);
  988. }
  989.  
  990. void
  991. windinit()
  992. {
  993.     Columns = 80;
  994.     P(P_LI) = Rows = 25;
  995. }
  996.  
  997. void
  998. windexit(r)
  999.     int             r;
  1000. {
  1001.     flushbuf();
  1002.     exit(r);
  1003. }
  1004.  
  1005. void
  1006. windgoto(r, c)
  1007.     register int    r, c;
  1008. {
  1009.     r += 1;
  1010.     c += 1;
  1011.  
  1012. /* I would recommend the following: 
  1013.     flushbuf();
  1014.     VioSetCurPos(r, c, 0);
  1015. Alex */
  1016.  
  1017.     /*
  1018.      * Check for overflow once, to save time. 
  1019.      */
  1020.     if (bpos + 8 >= BSIZE)
  1021.     flushbuf();
  1022.  
  1023.     outbuf[bpos++] = '\033';
  1024.     outbuf[bpos++] = '[';
  1025.     if (r >= 10)
  1026.     outbuf[bpos++] = r / 10 + '0';
  1027.     outbuf[bpos++] = r % 10 + '0';
  1028.     outbuf[bpos++] = ';';
  1029.     if (c >= 10)
  1030.     outbuf[bpos++] = c / 10 + '0';
  1031.     outbuf[bpos++] = c % 10 + '0';
  1032.     outbuf[bpos++] = 'H';
  1033. }
  1034.  
  1035. FILE           *
  1036. fopenb(fname, mode)
  1037.     char           *fname;
  1038.     char           *mode;
  1039. {
  1040.     FILE           *fopen();
  1041.     char            modestr[16];
  1042.  
  1043.     sprintf(modestr, "%sb", mode);
  1044.     return fopen(fname, modestr);
  1045. }
  1046. SHAR_EOF
  1047. cat << \SHAR_EOF > stevie.h
  1048. /*
  1049.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  1050.  *
  1051.  * Code Contributions By : Tim Thompson           twitch!tjt
  1052.  *                         Tony Andrews           onecom!wldrdg!tony 
  1053.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  1054.  */
  1055.  
  1056. #include "env.h"
  1057.  
  1058. #include <stdio.h>
  1059. #ifndef ATARI
  1060. # ifndef UNIX
  1061. #   include <stdlib.h>
  1062. # endif
  1063. #endif
  1064. #include <ctype.h>
  1065. #ifndef MWC
  1066. # include <string.h>
  1067. #endif
  1068. #include "ascii.h"
  1069. #include "keymap.h"
  1070. #include "param.h"
  1071. #include "term.h"
  1072. #include "macros.h"
  1073.  
  1074. #ifdef AMIGA
  1075. /*
  1076.  * This won't be needed if you have a version of Lattice 4.01 without broken
  1077.  * break signal handling.
  1078.  */
  1079. #include <signal.h>
  1080. #endif
  1081.  
  1082. extern char    *strchr();
  1083.  
  1084. #define NORMAL             0
  1085. #define CMDLINE             1
  1086. #define INSERT             2
  1087. #define APPEND             3
  1088. #define UNDO             4
  1089. #define REDO             5
  1090. #define PUT             6
  1091. #define FORWARD             7
  1092. #define BACKWARD         8
  1093. #define VALID             9
  1094. #define NOT_VALID        10
  1095. #define VALID_TO_CURSCHAR    11
  1096.  
  1097. /*
  1098.  * Boolean type definition and constants 
  1099.  */
  1100. typedef int     bool_t;
  1101.  
  1102. #ifndef    TRUE
  1103. #define    FALSE    (0)
  1104. #define    TRUE    (1)
  1105. #endif
  1106. #define    SORTOF    (2)
  1107. #define YES      TRUE
  1108. #define NO       FALSE
  1109. #define MAYBE    SORTOF
  1110.  
  1111. /*
  1112.  * Maximum screen dimensions
  1113.  */
  1114. #define MAX_COLUMNS 140L
  1115.  
  1116. /*
  1117.  * Buffer sizes
  1118.  */
  1119. #define CMDBUFFSIZE MAX_COLUMNS    /* size of the command processing buffer */
  1120.  
  1121. #define LSIZE        512    /* max. size of a line in the tags file */
  1122.  
  1123. #define IOSIZE     (1024+1)    /* file i/o and sprintf buffer size */
  1124.  
  1125. #define YANKSIZE    5200    /* yank buffer size */
  1126. #define INSERT_SIZE 5300    /* insert, redo and undo buffer size must be
  1127.                  * bigger than YANKSIZE */
  1128. #define REDO_UNDO_SIZE 5400    /* redo, undo and (undo an undo) buffer size
  1129.                  * must be bigger than INSERT_SIZE */
  1130. #define READSIZE    5500    /* read buffer size must be bigger than
  1131.                  * YANKSIZE and REDO_UNDO_SIZE */
  1132.  
  1133. /*
  1134.  * SLOP is the amount of extra space we get for text on a line during editing
  1135.  * operations that need more space. This keeps us from calling alloc every
  1136.  * time we get a character during insert mode. No extra space is allocated
  1137.  * when the file is initially read. 
  1138.  */
  1139. #define    SLOP    10
  1140.  
  1141. /*
  1142.  * LINEINC is the gap we leave between the artificial line numbers. This
  1143.  * helps to avoid renumbering all the lines every time a new line is
  1144.  * inserted. 
  1145.  *
  1146.  * Since line numbers are stored in longs (32 bits), a LINEINC of 10000
  1147.  * lets us have > 200,000 lines and we won't have to renumber very often.
  1148.  */
  1149. #define    LINEINC    10000
  1150.  
  1151. #define CHANGED   { Changed = TRUE; }
  1152. #define UNCHANGED { Changed = FALSE; }
  1153.  
  1154. struct line {
  1155.     struct line    *next;    /* next line */
  1156.     struct line    *prev;    /* previous line */
  1157.     char           *s;        /* text for this line */
  1158.     int             size;    /* actual size of space at 's' */
  1159.     unsigned long   num;    /* line "number" */
  1160. };
  1161.  
  1162. #define    LINEOF(x)    ((x)->linep->num)
  1163.  
  1164. struct lptr {
  1165.     struct line    *linep;    /* line we're referencing */
  1166.     int             index;    /* position within that line */
  1167. };
  1168.  
  1169. typedef struct line LINE;
  1170. typedef struct lptr LPtr;
  1171.  
  1172. struct charinfo {
  1173.     char            ch_size;
  1174.     char           *ch_str;
  1175. };
  1176.  
  1177. extern struct charinfo chars[];
  1178.  
  1179. extern int      State;
  1180. extern int      Rows;
  1181. extern int      Columns;
  1182. extern char    *Realscreen;
  1183. extern char    *Nextscreen;
  1184. extern int      NumLineSizes;
  1185. extern LINE   **LinePointers;
  1186. extern char    *LineSizes;
  1187. extern char    *Filename;
  1188. extern LPtr    *Filemem;
  1189. extern LPtr    *Filetop;
  1190. extern LPtr    *Fileend;
  1191. extern LPtr    *Topchar;
  1192. extern LPtr    *Botchar;
  1193. extern LPtr    *Curschar;
  1194. extern LPtr    *Insstart;
  1195. extern int      Cursrow, Curscol, Cursvcol, Curswant;
  1196. extern bool_t   set_want_col;
  1197. extern int      Prenum;
  1198. extern bool_t   Changed;
  1199. extern bool_t   RedrawingDisabled;
  1200. extern bool_t   MustRedrawLine;
  1201. extern bool_t   MustRedrawScreen;
  1202. extern bool_t   UndoInProgress;
  1203. extern bool_t   Binary;
  1204. extern char    *IObuff;
  1205. extern char    *Insbuffptr;
  1206. extern char    *Insbuff;
  1207. extern char    *Readbuffptr;
  1208. extern char    *Readbuff;
  1209. extern char    *Redobuffptr;
  1210. extern char    *Redobuff;
  1211. extern char    *Undobuffptr;
  1212. extern char    *Undobuff;
  1213. extern char    *UndoUndobuffptr;
  1214. extern char    *UndoUndobuff;
  1215. extern char    *Yankbuffptr;
  1216. extern char    *Yankbuff;
  1217. extern char     last_command;
  1218. extern char     last_command_char;
  1219.  
  1220. extern char    *strcpy();
  1221.  
  1222. /* alloc.c */
  1223. char  *alloc();
  1224. char  *strsave();
  1225. void   screenalloc(), filealloc(), freeall();
  1226. LINE  *newline();
  1227. bool_t canincrease();
  1228.  
  1229. /* cmdline.c */
  1230. void   readcmdline();
  1231. void   dotag();
  1232. void   msg(), emsg(), smsg();
  1233. void   gotocmdline();
  1234. void   wait_return();
  1235.  
  1236. /* dec.c */
  1237. int    dec();
  1238.  
  1239. /* edit.c */
  1240. void   edit(), insertchar(), getout(), scrollup(), scrolldown(), beginline();
  1241. bool_t oneright(), oneleft(), oneup(), onedown();
  1242.  
  1243. /* fileio.c */
  1244. void   filemess(), renum();
  1245. bool_t readfile(), writeit();
  1246.  
  1247. /* updateNs.c */
  1248. void   updateNextscreen();
  1249.  
  1250. /* updateRs.c */
  1251. void   updateRealscreen();
  1252.  
  1253. /* help.c */
  1254. bool_t help();
  1255.  
  1256. /* inc.c */
  1257. int    inc();
  1258.  
  1259. /* linefunc.c */
  1260. LPtr   *nextline(), *prevline(), *coladvance();
  1261.  
  1262. /* main.c */
  1263. void   stuffReadbuff();
  1264. void   stuffnumReadbuff();
  1265. char   vgetc();
  1266. char   vpeekc();
  1267.  
  1268. /* mark.c */
  1269. void   setpcmark(), clrall(), clrmark();
  1270. bool_t setmark();
  1271. LPtr  *getmark();
  1272.  
  1273. /* misccmds.c */
  1274. bool_t OpenForward();
  1275. bool_t OpenBackward();
  1276. void   fileinfo(), inschar(), insstr(), delline();
  1277. bool_t delchar();
  1278. int    cntllines(), plines();
  1279. LPtr  *gotoline();
  1280.  
  1281. /* normal.c */
  1282. void   normal();
  1283. void   ResetBuffers();
  1284. void   AppendToInsbuff();
  1285. void   AppendToRedobuff();
  1286. void   AppendNumberToRedobuff();
  1287. void   AppendToUndobuff();
  1288. void   AppendNumberToUndobuff();
  1289. void   AppendPositionToUndobuff();
  1290. void   AppendToUndoUndobuff();
  1291. void   AppendNumberToUndoUndobuff();
  1292. void   AppendPositionToUndoUndobuff();
  1293. bool_t linewhite();
  1294.  
  1295. /* mk.c */
  1296. char  *mkstr();
  1297. char  *mkline();
  1298.  
  1299. /* param.c */
  1300. void   doset();
  1301.  
  1302. /* screen.c */
  1303. void   nexttoscreen();
  1304. void   updateline();
  1305. void   redrawline();
  1306. void   screenclear();
  1307. void   cursupdate();
  1308. void   prt_line();
  1309. void   s_del();
  1310. void   s_ins();
  1311.  
  1312. /* search.c */
  1313. void   doglob();
  1314. void   dosub();
  1315. void   searchagain();
  1316. bool_t dosearch();
  1317. bool_t repsearch();
  1318. bool_t searchc(), crepsearch(), findfunc();
  1319. LPtr  *showmatch();
  1320. LPtr  *fwd_word(), *bck_word(), *end_word();
  1321.  
  1322. /*
  1323.  * Machine-dependent routines. 
  1324.  */
  1325. #ifdef AMIGA
  1326. # include "amiga.h"
  1327. #endif
  1328. #ifdef BSD
  1329. # include "bsd.h"
  1330. #endif
  1331. #ifdef UNIX
  1332. # include "unix.h"
  1333. #endif
  1334. #ifdef TOS
  1335. # include "tos.h"
  1336. #endif
  1337. #ifdef OS2
  1338. # include "os2.h"
  1339. #endif
  1340. #ifdef DOS
  1341. # include "dos.h"
  1342. #endif
  1343. SHAR_EOF
  1344. cat << \SHAR_EOF > tags
  1345. ISSPECIAL    edit.c    /^#define    ISSPECIAL(c)    ((c) == BS || (c) == NL || (c/
  1346. alloc    alloc.c    /^alloc(size)$/
  1347. badcmd    cmdline.c    /^badcmd()$/
  1348. beginline    edit.c    /^beginline(flag)$/
  1349. canincrease    alloc.c    /^canincrease(n)$/
  1350. dec    dec.c    /^dec(lp)$/
  1351. doecmd    cmdline.c    /^doecmd(arg, force)$/
  1352. doshell    cmdline.c    /^doshell()$/
  1353. dotag    cmdline.c    /^dotag(tag, force)$/
  1354. edit    edit.c    /^edit()$/
  1355. emsg    cmdline.c    /^emsg(s)$/
  1356. filealloc    alloc.c    /^filealloc()$/
  1357. freeall    alloc.c    /^freeall()$/
  1358. get_line    cmdline.c    /^get_line(cp)$/
  1359. get_range    cmdline.c    /^get_range(cp)$/
  1360. getout    edit.c    /^getout(r)$/
  1361. gotocmdline    cmdline.c    /^gotocmdline(clr, firstc)$/
  1362. insertchar    edit.c    /^insertchar(c)$/
  1363. msg    cmdline.c    /^msg(s)$/
  1364. newline    alloc.c    /^newline(nchars)$/
  1365. onedown    edit.c    /^onedown(n)$/
  1366. oneleft    edit.c    /^oneleft()$/
  1367. oneright    edit.c    /^oneright()$/
  1368. oneup    edit.c    /^oneup(n)$/
  1369. readcmdline    cmdline.c    /^readcmdline(firstc, cmdline)$/
  1370. screenalloc    alloc.c    /^screenalloc()$/
  1371. scrolldown    edit.c    /^scrolldown(nlines)$/
  1372. scrollup    edit.c    /^scrollup(nlines)$/
  1373. smsg    cmdline.c    /^smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9)$/
  1374. strsave    alloc.c    /^strsave(string)$/
  1375. wait_return    cmdline.c    /^wait_return()$/
  1376. Mmain    main.c    /^main(argc, argv)$/
  1377. clrall    mark.c    /^clrall()$/
  1378. clrmark    mark.c    /^clrmark(line)$/
  1379. coladvance    linefunc.c    /^coladvance(p, col)$/
  1380. filemess    fileio.c    /^filemess(s)$/
  1381. getmark    mark.c    /^getmark(c)$/
  1382. help    help.c    /^help()$/
  1383. inc    inc.c    /^inc(lp)$/
  1384. longline    help.c    /^longline(p)$/
  1385. nextline    linefunc.c    /^nextline(curr)$/
  1386. prevline    linefunc.c    /^prevline(curr)$/
  1387. readfile    fileio.c    /^readfile(fname, fromp, nochangename)$/
  1388. renum    fileio.c    /^renum()$/
  1389. setmark    mark.c    /^setmark(c)$/
  1390. setpcmark    mark.c    /^setpcmark()$/
  1391. stuffReadbuff    main.c    /^stuffReadbuff(s)$/
  1392. stuffnumReadbuff    main.c    /^stuffnumReadbuff(n)$/
  1393. usage    main.c    /^usage()$/
  1394. vgetc    main.c    /^vgetc()$/
  1395. vpeekc    main.c    /^vpeekc()$/
  1396. writeit    fileio.c    /^writeit(fname, start, end)$/
  1397. AppendNumberToRedobuff    normal.c    /^AppendNumberToRedobuff(n)$/
  1398. AppendNumberToUndoUndobuff    normal.c    /^AppendNumberToUndoUndobuff(n)$/
  1399. AppendNumberToUndobuff    normal.c    /^AppendNumberToUndobuff(n)$/
  1400. AppendPositionToUndoUndobuff    normal.c    /^AppendPositionToUndoUndobuff(column, row)$/
  1401. AppendPositionToUndobuff    normal.c    /^AppendPositionToUndobuff(column, row)$/
  1402. AppendToInsbuff    normal.c    /^AppendToInsbuff(s)$/
  1403. AppendToRedobuff    normal.c    /^AppendToRedobuff(s)$/
  1404. AppendToUndoUndobuff    normal.c    /^AppendToUndoUndobuff(s)$/
  1405. AppendToUndobuff    normal.c    /^AppendToUndobuff(s)$/
  1406. DEFAULT1    normal.c    /^#define    DEFAULT1(x)    (((x) == 0) ? 1 : (x))$/
  1407. IDCHAR    normal.c    /^#define    IDCHAR(c)    (isalpha(c) || isdigit(c) || (c)/
  1408. OpenBackward    misccmds.c    /^OpenBackward(can_ai)$/
  1409. OpenForward    misccmds.c    /^OpenForward(can_ai)$/
  1410. ResetBuffers    normal.c    /^ResetBuffers()$/
  1411. cntllines    misccmds.c    /^cntllines(pbegin, pend)$/
  1412. cooked    raw.c    /^cooked(fp)$/
  1413. cursupdate    screen.c    /^cursupdate()$/
  1414. delchar    misccmds.c    /^delchar(fixpos, undo)$/
  1415. delline    misccmds.c    /^delline(nlines, can_update)$/
  1416. dochange    normal.c    /^dochange()$/
  1417. dodelete    normal.c    /^dodelete(redraw, setup_for_undo, try_to_yank)$/
  1418. dojoin    normal.c    /^dojoin(leading_space, strip_leading_spaces)$/
  1419. doput    normal.c    /^doput(dir)$/
  1420. doset    param.c    /^doset(arg, inter)$/
  1421. doshift    normal.c    /^doshift(op)$/
  1422. doyank    normal.c    /^doyank()$/
  1423. fileinfo    misccmds.c    /^fileinfo()$/
  1424. gotoline    misccmds.c    /^gotoline(n)$/
  1425. inschar    misccmds.c    /^inschar(c)$/
  1426. insstr    misccmds.c    /^insstr(s)$/
  1427. linewhite    normal.c    /^linewhite(p)$/
  1428. normal    normal.c    /^normal(c)$/
  1429. plines    misccmds.c    /^plines(p)$/
  1430. prt_line    screen.c    /^prt_line(s)$/
  1431. raw    raw.c    /^raw(fp)$/
  1432. redrawline    screen.c    /^redrawline()$/
  1433. s_del    screen.c    /^s_del(row, nlines)$/
  1434. s_ins    screen.c    /^s_ins(row, nlines)$/
  1435. screenclear    screen.c    /^screenclear()$/
  1436. showparms    param.c    /^showparms(all)$/
  1437. startinsert    normal.c    /^startinsert(startln)$/
  1438. tabinout    normal.c    /^tabinout(shift_type, num)$/
  1439. updateline    screen.c    /^updateline()$/
  1440. C0    search.c    /^#define    C0(c)    (((c) == ' ') || ((c) == '\\t') || ((/
  1441. C1    search.c    /^#define    C1(c)    (isalpha(c) || isdigit(c) || ((c) ==/
  1442. OTHERDIR    search.c    /^#define    OTHERDIR(x)    (((x) == FORWARD) ? BACKWARD :/
  1443. SendPacket    sendpacket.c    /^SendPacket(pid, action, args, nargs)$/
  1444. bck_word    search.c    /^bck_word(p, type)$/
  1445. bcksearch    search.c    /^bcksearch(str)$/
  1446. cls    search.c    /^cls(c)$/
  1447. crepsearch    search.c    /^crepsearch(flag)$/
  1448. doglob    search.c    /^doglob(lp, up, cmd)$/
  1449. dosearch    search.c    /^dosearch(dir, str)$/
  1450. dosub    search.c    /^dosub(lp, up, cmd)$/
  1451. end_word    search.c    /^end_word(p, type)$/
  1452. findfunc    search.c    /^findfunc(dir)$/
  1453. fwd_word    search.c    /^fwd_word(p, type)$/
  1454. fwdsearch    search.c    /^fwdsearch(str)$/
  1455. mapstring    search.c    /^mapstring(s)$/
  1456. regerror    search.c    /^regerror(s)$/
  1457. repsearch    search.c    /^repsearch(flag)$/
  1458. searchagain    search.c    /^searchagain(dir)$/
  1459. searchc    search.c    /^searchc(c, dir, type)$/
  1460. showmatch    search.c    /^showmatch()$/
  1461. ssearch    search.c    /^ssearch(dir, str)$/
  1462. updateNextscreen    updateNs.c    /^updateNextscreen(type)$/
  1463. CTRL    ascii.h    /^#define    CTRL(x)    ((x) & 0x1f)$/
  1464. updateRealscreen    updateRs.c    /^updateRealscreen()$/
  1465. LINE    stevie.h    122
  1466. LINEOF    stevie.h    /^#define    LINEOF(x)    ((x)->linep->num)$/
  1467. LPTR    stevie.h    123
  1468. P    param.h    /^#define    P(n)    (params[n].value)$/
  1469. RowNumber    macros.h    /^#define RowNumber(p) (UndoInProgress ? 0 : cntllin/
  1470. anyinput    macros.h    /^#define anyinput() (Readbuffptr != NULL)$/
  1471. bool_t    stevie.h    53
  1472. buf1line    macros.h    /^#define buf1line() (Filemem->linep->next == Fileen/
  1473. bufempty    macros.h    /^#define bufempty() (buf1line() && Filemem->linep->/
  1474. endofline    macros.h    /^#define endofline(p) \\$/
  1475. equal    macros.h    /^#define equal(a, b) (((a)->linep == (b)->linep) &&/
  1476. gchar    macros.h    /^#define gchar(lp) ((lp)->linep->s[(lp)->index])$/
  1477. gt    macros.h    /^#define gt(a, b) ((LINEOF(a) != LINEOF(b)) \\$/
  1478. gtoreq    macros.h    /^#define gtoreq(a, b) ((LINEOF(a) != LINEOF(b)) \\$/
  1479. lineempty    macros.h    /^#define lineempty(p) ((p)->linep->s[0] == NUL)$/
  1480. lt    macros.h    /^#define lt(a, b) ((LINEOF(a) != LINEOF(b)) \\$/
  1481. ltoreq    macros.h    /^#define ltoreq(a, b) ((LINEOF(a) != LINEOF(b)) \\$/
  1482. mkline    mk.c    /^mkline(n)$/
  1483. mkstr    mk.c    /^mkstr(c)$/
  1484. pchar    macros.h    /^#define pchar(lp, c) ((lp)->linep->s[(lp)->index] /
  1485. pswap    macros.h    /^#define pswap(a, b) { LPTR pswaptmp; pswaptmp = a;/
  1486. startofline    macros.h    /^#define startofline(p) ((p)->index == 0)$/
  1487. GetCharacter    amiga.c    /^GetCharacter()$/
  1488. beep    amiga.c    /^beep()$/
  1489. delay    amiga.c    /^delay()$/
  1490. flushbuf    amiga.c    /^flushbuf()$/
  1491. fopenb    amiga.c    /^fopenb(fname, mode)$/
  1492. getCSIsequence    amiga.c    /^getCSIsequence()$/
  1493. inchar    amiga.c    /^inchar()$/
  1494. outchar    amiga.c    /^outchar(c)$/
  1495. outone    amiga.c    /^#define    outone(c)    outbuf[bpos++] = c; if (bpos >= /
  1496. outstr    amiga.c    /^outstr(s)$/
  1497. sleep    amiga.c    /^sleep(n)$/
  1498. windexit    amiga.c    /^windexit(r)$/
  1499. windgoto    amiga.c    /^windgoto(r, c)$/
  1500. windinit    amiga.c    /^windinit()$/
  1501. SHAR_EOF
  1502. cat << \SHAR_EOF > term.h
  1503. /*
  1504.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  1505.  *
  1506.  * Code Contributions By : Tim Thompson           twitch!tjt
  1507.  *                         Tony Andrews           onecom!wldrdg!tony 
  1508.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  1509.  */
  1510.  
  1511. /*
  1512.  * This file contains the machine dependent escape sequences that the editor
  1513.  * needs to perform various operations. Some of the sequences here are
  1514.  * optional. Anything not available should be indicated by a null string. In
  1515.  * the case of insert/delete line sequences, the editor checks the capability
  1516.  * and works around the deficiency, if necessary. 
  1517.  *
  1518.  * Currently, insert/delete line sequences are used for screen scrolling. There
  1519.  * are lots of terminals that have 'index' and 'reverse index' capabilities,
  1520.  * but no line insert/delete. For this reason, the editor routines s_ins()
  1521.  * and s_del() should be modified to use 'index' sequences when the line to
  1522.  * be inserted or deleted at line zero. 
  1523.  */
  1524.  
  1525. /*
  1526.  * The macro names here correspond (more or less) to the actual ANSI names 
  1527.  */
  1528.  
  1529. #ifdef    ATARI
  1530. #define    T_EL    "\033l"        /* erase the entire current line */
  1531. #define    T_IL    "\033L"        /* insert one line */
  1532. #define    T_IL_B    ""
  1533. #define    T_DL    "\033M"        /* delete one line */
  1534. #define    T_DL_B    ""
  1535. #define    T_SC    "\033j"        /* save the cursor position */
  1536. #define    T_ED    "\033E"        /* erase display (may optionally home cursor) */
  1537. #define    T_RC    "\033k"        /* restore the cursor position */
  1538. #define    T_CI    "\033f"        /* invisible cursor (very optional) */
  1539. #define    T_CV    "\033e"        /* visible cursor (very optional) */
  1540. #define T_TP    ""        /* plain text */
  1541. #define T_TI    ""        /* inverse-video text */
  1542. #endif
  1543.  
  1544. #ifdef    UNIX
  1545. /*
  1546.  * The UNIX sequences are hard-wired for ansi-like terminals. I should really
  1547.  * use termcap/terminfo, but the UNIX port was done for profiling, not for
  1548.  * actual use, so it wasn't worth the effort. 
  1549.  */
  1550. #define    T_EL    "\033[2K"    /* erase the entire current line */
  1551. #define    T_IL    "\033[L"    /* insert one line */
  1552. #define    T_IL_B    ""
  1553. #define    T_DL    "\033[M"    /* delete one line */
  1554. #define    T_DL_B    ""
  1555. #define    T_ED    "\033[2J"    /* erase display (may optionally home cursor) */
  1556. #define    T_SC    "\0337"        /* save the cursor position */
  1557. #define    T_RC    "\0338"        /* restore the cursor position */
  1558. #define    T_CI    ""        /* invisible cursor (very optional) */
  1559. #define    T_CV    ""        /* visible cursor (very optional) */
  1560. #define T_TP    ""        /* plain text */
  1561. #define T_TI    ""        /* inverse-video text */
  1562. #endif
  1563.  
  1564. #ifdef    BSD
  1565. /* The BSD 4.3 sequences are hard-wired for ansi-like terminals. */
  1566. #define    T_EL    "\033[2K"    /* erase the entire current line */
  1567. #define    T_IL    "\033[L"    /* insert line */
  1568. #define    T_IL_B    ""
  1569. #define    T_DL    "\033[M"    /* delete line */
  1570. #define    T_DL_B    ""
  1571. #define    T_ED    "\033[2J"    /* erase display (may optionally home cursor) */
  1572. #define    T_SC    ""        /* save the cursor position */
  1573. #define    T_RC    ""        /* restore the cursor position */
  1574. #define    T_CI    ""        /* invisible cursor (very optional) */
  1575. #define    T_CV    ""        /* visible cursor (very optional) */
  1576. #define T_TP    ""        /* plain text */
  1577. #define T_TI    ""        /* inverse-video text */
  1578. #endif
  1579.  
  1580. #ifdef    OS2
  1581. /*
  1582.  * The OS/2 ansi console driver is pretty deficient. No insert or delete line
  1583.  * sequences. The erase line sequence only erases from the cursor to the end
  1584.  * of the line. For our purposes that works out okay, since the only time
  1585.  * T_EL is used is when the cursor is in column 0.
  1586.  *
  1587.  * The insert/delete line sequences marked here are actually implemented in
  1588.  * the file os2.c using direct OS/2 system calls. This makes the capability
  1589.  * available for the rest of the editor via appropriate escape sequences
  1590.  * passed to outstr().
  1591.  */
  1592. #define    T_EL    "\033[K"    /* erase the entire current line */
  1593. #define    T_IL    "\033[L"    /* insert one line - fake (see os2.c) */
  1594. #define    T_IL_B    ""
  1595. #define    T_DL    "\033[M"    /* delete one line - fake (see os2.c) */
  1596. #define    T_DL_B    ""
  1597. #define    T_ED    "\033[2J"    /* erase display (may optionally home cursor) */
  1598. #define    T_SC    "\033[s"    /* save the cursor position */
  1599. #define    T_RC    "\033[u"    /* restore the cursor position */
  1600. #define    T_CI    ""        /* invisible cursor (very optional) */
  1601. #define    T_CV    ""        /* visible cursor (very optional) */
  1602. #define T_TP    ""        /* plain text */
  1603. #define T_TI    ""        /* inverse-video text */
  1604. #endif
  1605.  
  1606. #ifdef AMIGA
  1607. /*
  1608.  * The erase line sequence only erases from the cursor to the end of the
  1609.  * line. For our purposes that works out okay, since the only time T_EL is
  1610.  * used is when the cursor is in column 0. 
  1611.  */
  1612. #define    T_EL    "\033[K"    /* erase the entire current line */
  1613. #define    T_IL    "\033["        /* insert line */
  1614. #define    T_IL_B    "L"
  1615. #define    T_DL    "\033["        /* delete line */
  1616. #define    T_DL_B    "M"
  1617. #define    T_ED    "\014"        /* erase display (may optionally home cursor) */
  1618. #define    T_RC    ""        /* restore the cursor position */
  1619. #define    T_SC    ""        /* save the cursor position */
  1620. #define    T_CI    "\033[0 p"    /* invisible cursor (very optional) */
  1621. #define    T_CV    "\033[1 p"    /* visible cursor (very optional) */
  1622. #define T_TP    "\033[0m"    /* plain text */
  1623. #define T_TI    "\033[7m"    /* inverse-video text */
  1624. #endif
  1625.  
  1626. #ifdef    DOS
  1627. /*
  1628.  * DOS sequences
  1629.  *
  1630.  * Some of the following sequences require the use of the "nansi.sys"
  1631.  * console driver. The standard "ansi.sys" driver doesn't support
  1632.  * sequences for insert/delete line.
  1633.  */
  1634. #define    T_EL    "\033[K"    /* erase the entire current line */
  1635. #define    T_IL    "\033[L"    /* insert line (requires nansi.sys driver) */
  1636. #define    T_IL_B    ""
  1637. #define    T_DL    "\033[M"    /* delete line (requires nansi.sys driver) */
  1638. #define    T_DL_B    ""
  1639. #define    T_ED    "\033[2J"    /* erase display (may optionally home cursor) */
  1640. #define    T_SC    "\033[s"    /* save the cursor position */
  1641. #define    T_RC    "\033[u"    /* restore the cursor position */
  1642. #define    T_CI    ""        /* invisible cursor (very optional) */
  1643. #define    T_CV    ""        /* visible cursor (very optional) */
  1644. #define T_TP    ""        /* plain text */
  1645. #define T_TI    ""        /* inverse-video text */
  1646. #endif
  1647. SHAR_EOF
  1648. cat << \SHAR_EOF > tos.h
  1649. /*
  1650.  * Atari Machine-dependent routines. 
  1651.  */
  1652.  
  1653. int  inchar();
  1654. void outchar();
  1655. void outstr(), beep();
  1656. void remove(), rename();
  1657. void windinit(), windexit(), windgoto();
  1658. void delay();
  1659. void sleep();
  1660. SHAR_EOF
  1661. cat << \SHAR_EOF > version.c
  1662. /*
  1663.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  1664.  *
  1665.  * Code Contributions By : Tim Thompson           twitch!tjt
  1666.  *                         Tony Andrews           onecom!wldrdg!tony 
  1667.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  1668.  */
  1669.  
  1670. /*
  1671.  * Version  Changes (and person who did them)
  1672.  * -------  ---------------------------------
  1673.  * 3.10     - version that started it all. Found on comp.sources.unix
  1674.  *            Jun88 Volume 15 i037, i038, i039, i040, i042, and INF3
  1675.  *          - Tim Thompson and Tony Andrews
  1676.  * 
  1677.  * 3.10A    - took version of STEVIE posted to usenet and added Amiga
  1678.  *            and BSD support; added undo and redo commands; sped up
  1679.  *            output to screen; sped up on-screen activities (such as
  1680.  *            cursoring); fixed miscellaneous small bugs and changed some
  1681.  *            commands so that they more closely resembled vi.
  1682.  *          - GRWalter (Fred)
  1683.  * 
  1684.  * 3.11B    - added the ability to be run in the background (STEVIE will
  1685.  *            attempt to use the current window, but if it can't then it
  1686.  *            will open its own window). Fixed some other miscellaneous
  1687.  *            bugs (some to do with re-sizing the screen, one to do with
  1688.  *            undo'ing changes on lines that start with whitespace).
  1689.  *          - GRWalter (Fred)
  1690.  * 
  1691.  * 3.11C    - fixed a bug that was causing the entire screen to be refreshed
  1692.  *            at the wrong times sometimes. Input mode was sped up as well
  1693.  *            as a bug involving lines that wrapped was fixed. Changed :ta
  1694.  *            a bit. Fixed bug triggered when files are > 6000 lines.
  1695.  *          - GRWalter (Fred)
  1696.  *
  1697.  * 3.31A    - Tony Andrews put out a divergent version of STEVIE (version 3.31).
  1698.  *            I moved the important stuff over into my version.
  1699.  *
  1700.  *            Here is a list of what was moved over :
  1701.  * 
  1702.  *************************************************************************
  1703.  * Revision 3.29  88/06/26  14:53:19  tony
  1704.  * Added support for a simple form of the "global" command. It supports
  1705.  * commands of the form "g/pat/d" or "g/pat/p", to delete or print lines
  1706.  * that match the given pattern. A range spec may be used to limit the
  1707.  * lines to be searched.
  1708.  * 
  1709.  * Revision 3.28  88/06/25  21:44:22  tony
  1710.  * Fixed a problem in the processing of colon commands that caused
  1711.  * substitutions of patterns containing white space to fail.
  1712.  * 
  1713.  * Revision 3.26  88/06/10  13:44:06  tony
  1714.  * Fixed a bug involving writing out files with long pathnames. A small
  1715.  * fixed size buffer was being used. The space for the backup file name
  1716.  * is now allocated dynamically.
  1717.  * 
  1718.  * Revision 1.12  88/05/03  14:39:52  tony
  1719.  * Also merged in support for DOS.
  1720.  * 
  1721.  * Revision 1.11  88/05/02  21:38:21  tony
  1722.  * The code that reads files now handles boundary/error conditions much
  1723.  * better, and generates status/error messages that are compatible with
  1724.  * the real vi. Also fixed a bug in repeated reverse searches that got
  1725.  * inserted in the recent changes to search.c.
  1726.  * 
  1727.  * Revision 1.10  88/05/02  07:35:41  tony
  1728.  * Fixed a bug in the routine plines() that was introduced during changes
  1729.  * made for the last version.
  1730.  * 
  1731.  * Revision 1.9  88/05/01  20:10:19  tony
  1732.  * Fixed some problems with auto-indent, and added support for the "number"
  1733.  * parameter.
  1734.  * 
  1735.  * Revision 1.8  88/04/30  20:00:49  tony
  1736.  * Added support for the auto-indent feature.
  1737.  * 
  1738.  * Revision 1.6  88/04/28  08:19:35  tony
  1739.  * Modified Henry Spencer's regular expression library to support new
  1740.  * features that couldn't be done easily with the existing interface.
  1741.  * This code is now a direct part of the editor source code. The editor
  1742.  * now supports the "ignorecase" parameter, and multiple substitutions
  1743.  * per line, as in "1,$s/foo/bar/g".
  1744.  * 
  1745.  * Revision 1.5  88/04/24  21:38:00  tony
  1746.  * Added preliminary support for the substitute command. Full range specs.
  1747.  * are supported, but only a single substitution is allowed on each line.
  1748.  * 
  1749.  * Revision 1.4  88/04/23  20:41:01  tony
  1750.  * Worked around a problem with adding lines to the end of the buffer when
  1751.  * the cursor is at the bottom of the screen (in misccmds.c). Also fixed a
  1752.  * bug that caused reverse searches from the start of the file to bomb.
  1753.  * 
  1754.  * Revision 1.3  88/03/24  08:57:00  tony
  1755.  * Fixed a bug in cmdline() that had to do with backspacing out of colon
  1756.  * commands or searches. Searches were okay, but colon commands backed out
  1757.  * one backspace too early.
  1758.  * 
  1759.  * Revision 1.2  88/03/21  16:47:55  tony
  1760.  * Fixed a bug in renum() causing problems with large files (>6400 lines).
  1761.  *************************************************************************
  1762.  *          - GRWalter (Fred)
  1763.  *
  1764.  * 3.32A    - added the :[range]d command. Played with 'p' and 'P'.
  1765.  *            Added undo capability to :s and :g//d commands.
  1766.  *            Added '%' as a line range specifier (entire file).
  1767.  *            Fixed search so that tags file from real ctags could be used.
  1768.  *            Fixed undo after delete everything operation.
  1769.  *            Made prt_line work in nu mode (so :g//p works right).
  1770.  *            Fixed ai mode (when there was text after the cursor it didn't ai).
  1771.  *            Fixed 'J' (didn't handle next line just having whitespace).
  1772.  *            Fixed :[range] so it behaves like the real vi (goes to highest
  1773.  *            line number in the given range).
  1774.  *            Made it so that the cursor is on the last char inserted instead
  1775.  *            the one right after when there is exactly 1 char right after.
  1776.  *            Made change operator work properly when it ended on the
  1777.  *            end of the line.
  1778.  *          - GRWalter (Fred)
  1779.  *
  1780.  * 3.33A    - no longer updateNextscreen when putting or undoing or
  1781.  *            redoing until I am done. 'p', 'u' and '.' thus sped up.
  1782.  *          - no longer recalculate line lengths when cursupdate() called,
  1783.  *            which speeds up lots'a things (like on-screen cursoring).
  1784.  *          - avoid redrawing (in updateNextscreen) as much as possible, which
  1785.  *            speeds up (among other things) cursoring (off screen), put, undo,
  1786.  *            redo, etc.
  1787.  *          - GRWalter (Fred)
  1788.  *
  1789.  * 3.34A    - rewrote updateNextscreen and updatenextline so they won't do as
  1790.  *            much work. Sped up cursoring off-screen. Fixed bug in cursupdate
  1791.  *            (could index through NULL pointer).
  1792.  *          - GRWalter (Fred)
  1793.  *
  1794.  * 3.35A    - Compiles with Lattice 5.0 now - needed miscellaneous changes.
  1795.  *          - Environment variables (EXINIT) finally used.
  1796.  *          - Stevie is now compiled so it's residentable.
  1797.  *          - Fixed bug in insstr() (caused problems with redo of inserts).
  1798.  *          - Fixed buffer overflow/corrupt messages.
  1799.  *          - Tweaked updateNextscreen routine some more.
  1800.  *          - Added __DATE__ and __TIME__ of compilation to help screen.
  1801.  *          - GRWalter (Fred)
  1802.  */
  1803.  
  1804. char           *Version = "STEVIE - Version 3.35A";
  1805. SHAR_EOF
  1806. #    End of shell archive
  1807. exit 0
  1808. -- 
  1809. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  1810. Have five nice days.
  1811.